#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#define PATH_NAME "."
#define PRO_ID  100
#define SZ 64


int main(int argc, char const *argv[])
{
    key_t key = ftok(PATH_NAME, PRO_ID);
    if (key == -1) {
        perror("ftok error");
    }
    // 先创建共享内存
    int shmid = shmget(key, SZ, IPC_CREAT | 0666);
    printf("shmid = %d\n", shmid);

    // 然后再删除共享内存
    int ret = shmctl(shmid, IPC_RMID, NULL);
    if (ret == -1) {
        perror("shmctl error");
        exit(EXIT_FAILURE);
    }
    printf("delete shm ok\n, ret = %d\n", ret);
    return 0;
}
